package com.biscuit.page.basicservice.utils;

import com.biscuit.page.basicservice.model.constant.NicknameConstant;

/**
 * @author biscuit
 * @createTime 2024/5/8 17:18
 */
public class TextUtil {

    /**
     * 获取随机昵称
     *
     * @return 随机昵称
     */
    public static String getRandomNickname() {
        String nicknamePrefix = NicknameConstant.NICKNAME_PREFIX_LIST.get(NumberUtil.randomNumberBySize(NicknameConstant.NICKNAME_PREFIX_LIST.size() - 1));
        String nicknameSuffix = NicknameConstant.NICKNAME_SUFFIX_LIST.get(NumberUtil.randomNumberBySize(NicknameConstant.NICKNAME_SUFFIX_LIST.size() - 1));
        String suffix1 = NicknameConstant.ENGLISH_LIST.get(NumberUtil.randomNumberBySize(25));
        String suffix2 = NicknameConstant.ENGLISH_LIST.get(NumberUtil.randomNumberBySize(25));
        String suffix3 = NicknameConstant.ENGLISH_LIST.get(NumberUtil.randomNumberBySize(25));
        return nicknamePrefix + nicknameSuffix + suffix1 + suffix2.toLowerCase() + suffix3.toLowerCase() + NumberUtil.randomNumberByLength(1);
    }

    /**
     * 去除字符串首尾 / 线
     */
    public static String trimOblique(String source) {
        return source.substring(
                source.charAt(0) == '/' ? 1 : 0,
                source.charAt(source.length() - 1) == '/' ? source.length() - 1 : source.length()
        );
    }

    /**
     * '{xxx}' 替换 *
     */
    public static String trimPathVariableReplaceWildcard(String source) {
        return source.replaceAll("\\{.*?\\}", "*");
    }

}
